//
//  MineBaseInfoViewController.m
//  Btpin
//
//  Created by Vic on 2019/3/17.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "MineBaseInfoViewController.h"
#import <Photos/Photos.h>
#import <AVFoundation/AVCaptureDevice.h>
#import <AVFoundation/AVMediaFormat.h>
#import "MineInfoEditViewController.h"
#import "SelcetCityViewController.h"
#import "MineInfoEditWXQRCodeViewController.h"
#import "PMineResumeInfoModel.h"
#import "RealNameAuthenticationViewController.h"
#import "LYSettingchangeMobileController.h"

@interface MineBaseInfoViewController ()<UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, TimeSelectPickerViewDelegate, PSSingleRowViewDelegate, MineInfoEditViewControllerDelegate, SelcetCityViewControllerDelegate, MineInfoEditWXQRCodeViewControllerDelegate>
{
    UIScrollView *bottomScrollView;
    UIImageView *photoImgView;
    PSSingleRowView *headerPickerView;
    
    NSString *url;
    NSString *wxPath;
    NSString *sex;
    NSString *experience;
    NSString *residence;
}
@property (nonatomic, strong) PMineResumeInfoModel *infoModel;
@property (nonatomic, strong) PSCell *nameCell;
@property (nonatomic, strong) PSCell *nicknameCell;
@property (nonatomic, strong) PSCell *genderCell;
@property (nonatomic, strong) PSCell *birthdayCell;
@property (nonatomic, strong) PSCell *experienceCell;
@property (nonatomic, strong) PSCell *addressCell;
@property (nonatomic, strong) PSCell *phoneNumberCell;
@property (nonatomic, strong) PSCell *emailCell;
@property (nonatomic, strong) PSCell *wxQRCodeCell;
@property (nonatomic, strong) PSSingleRowView *genderPickerView;
@property (nonatomic, strong) TimeSelectPickerView *birthdayPickerView;
@property (nonatomic, strong) PSSingleRowView *experiencePickerView;
@end

@implementation MineBaseInfoViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    if (headerPickerView) {
        headerPickerView.hidden = YES;
    }
    if (self.genderPickerView) {
        self.genderPickerView.hidden = YES;
    }
    if (self.birthdayPickerView) {
        self.birthdayPickerView.hidden = YES;
    }
    if (self.experiencePickerView) {
        self.experiencePickerView.hidden = YES;
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    url = @"";
    wxPath = @"";
    sex = @"";
    experience = @"";
    residence = @"";
    
    [self loadData];
//    [self initUI];
}
- (void)loadData {
    SVPHUDShow;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    __weak __typeof(self)weakSelf = self;
    [BaseNetManager requestWithMethod:POST path:Person_GetMineProfile_URL params:dic successBlock:^(NSDictionary *responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            __strong __typeof(weakSelf)strongSelf = weakSelf;
            id data = responseObject[@"data"];
            strongSelf.infoModel = [[PMineResumeInfoModel alloc] init];
            [strongSelf.infoModel setValuesForKeysWithDictionary:data];
            UD_SetOForK(strongSelf.infoModel.telephone, isMobile);
            UDSynchronize;
            [strongSelf initUI];
            SVPHUDDismiss;
        } else {
            SVPHUDError(responseObject[@"msg"]);
        }
    } failurBlock:^(NSError *error) {
        SVPHUDError(NetErrorAlertText);
    }];
}
- (void)initUI {
    self.navigationItem.title = @"基本资料";
    
    if (self.infoModel.avatar && self.infoModel.avatar.length) {
        url = self.infoModel.avatar;
    }
    if (self.infoModel.weixin_img && self.infoModel.weixin_img.length) {
        wxPath = self.infoModel.weixin_img;
    }
    if (self.infoModel.sex) {
        sex = self.infoModel.sex;
    }
    if (self.infoModel.experience) {
        experience = self.infoModel.experience;
    }
    if (self.infoModel.residence) {
        residence = self.infoModel.residence;
    }
    
    UIButton *okBtn = [UIToolsControl initButtonWithFrame:CGRectMake(WIDTH-50*Scale, HeightOfStatusBar+3*Scale, 50*Scale, 36*Scale) imageName:nil target:self action:@selector(okBtnTap) title:@"确定" titleColor:THEMECOLOR_OF_ORANGE];
    okBtn.titleLabel.font = Font(Font_15);
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:okBtn];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    bottomScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-SIMEmojKeyBoardkBottomNOSafeArea_Height-HeightOfStatusBarAndNavigationBar)];
    [self.view addSubview:bottomScrollView];
    
    UILabel *photoTitleLbl = [UIToolsControl initLabelWithFrame:CGRectMake(30*Scale, 10*Scale, WIDTH-60*Scale, PSCellHeight) text:@"简历照片" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_13];
    [bottomScrollView addSubview:photoTitleLbl];
    [photoTitleLbl borderColor:THEMECOLOR_OF_TEXT_cccccc borderWidth:lineH borderType:BorderSideTypeBottom];
    photoImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(ViewWidth(photoTitleLbl)-62*Scale, 4*Scale, 62*Scale, 62*Scale) imageName:@"header_bg"];
    photoImgView.contentMode = UIViewContentModeScaleAspectFill;
    photoImgView.contentMode = UIViewContentModeScaleAspectFill;
    photoImgView.layer.cornerRadius = 31*Scale;
    photoImgView.layer.masksToBounds = YES;
    [photoTitleLbl addSubview:photoImgView];
    if (self.infoModel && self.infoModel.avatar.length) {
        [photoImgView sd_setImageWithURL:[NSURL URLWithString:self.infoModel.avatar]];
    }
    UIButton *photoBtn = [UIToolsControl initButtonWithFrame:photoTitleLbl.frame imageName:nil target:self action:@selector(photoBtnTap) title:nil titleColor:nil];
    [bottomScrollView addSubview:photoBtn];
    
    NSMutableArray *headerArray = [NSMutableArray arrayWithCapacity:0];
    PublicCategoryElementModel *model1 = [[PublicCategoryElementModel alloc] init];
    [model1 setValuesForKeysWithDictionary:@{@"id":@"0", @"name":@"拍摄"}];
    [headerArray addObject:model1];
    PublicCategoryElementModel *model2 = [[PublicCategoryElementModel alloc] init];
    [model2 setValuesForKeysWithDictionary:@{@"id":@"1", @"name":@"相册"}];
    [headerArray addObject:model2];
    headerPickerView = [[PSSingleRowView alloc] initWithData:headerArray target:self];
    headerPickerView.hidden = YES;
    
    __weak __typeof(self)weakSelf = self;
    self.genderPickerView = [[PSSingleRowView alloc] initWithData:[DataToolsControl sharedManager].allCategoryInfoModel.sexArray target:self];
    self.genderPickerView.hidden = YES;
    self.birthdayPickerView = [[TimeSelectPickerView alloc] initWithTarget:self time:nil timeSelectPickerType:TimeSelectPickerTypeOfBirthday dateFormat:nil];
    self.birthdayPickerView.hidden = YES;
    self.experiencePickerView = [[PSSingleRowView alloc] initWithData:[DataToolsControl sharedManager].allCategoryInfoModel.experienceArray target:self];
    self.experiencePickerView.hidden = YES;
    
    self.nameCell = [[PSCell alloc] initWithFrame:CGRectMake(StartX(photoTitleLbl), EndY(photoTitleLbl), ViewWidth(photoTitleLbl), PSCellHeight) title:@"姓名" text:((self.infoModel && self.infoModel.name)?self.infoModel.name:nil) placeholder:@"请输入姓名" cellType:PSCellTypeOfIndicator];
//    nameCell.textField.textColor = THEMECOLOR_OF_TEXT_cccccc;
    self.nameCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        RealNameAuthenticationViewController *RNAVC = [[RealNameAuthenticationViewController alloc] init];
        RNAVC.setok = ^(NSString *name) {
            if (name && name.length) {
                strongSelf.nameCell.textField.text = name;
            }
        };
        RNAVC.hidesBottomBarWhenPushed = YES;
        [strongSelf.navigationController pushViewController:RNAVC animated:YES];
//        [strongSelf pushInfoEditVC:InfoEditTypeOfName];
    };
    [bottomScrollView addSubview:self.nameCell];
    
    self.nicknameCell = [[PSCell alloc] initWithFrame:CGRectMake(StartX(photoTitleLbl), EndY(self.nameCell), ViewWidth(photoTitleLbl), PSCellHeight) title:@"昵称花名" text:((self.infoModel && self.infoModel.nickname)?self.infoModel.nickname:@"") placeholder:@"请输入昵称花名" cellType:PSCellTypeOfIndicator];
    self.nicknameCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf pushInfoEditVC:InfoEditTypeOfNickName];
    };
    [bottomScrollView addSubview:self.nicknameCell];
    
    self.genderCell = [[PSCell alloc] initWithFrame:CGRectMake(StartX(photoTitleLbl), EndY(self.nicknameCell), ViewWidth(photoTitleLbl), PSCellHeight) title:@"性别" text:((self.infoModel && self.infoModel.sex)?(([self.infoModel.sex integerValue]==1)?@"男":@"女"):@"") placeholder:@"男/女" cellType:PSCellTypeOfIndicator];
    self.genderCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.genderPickerView.hidden = NO;
    };
    [bottomScrollView addSubview:self.genderCell];
    sex = self.infoModel.sex;
    
    self.birthdayCell = [[PSCell alloc] initWithFrame:CGRectMake(StartX(photoTitleLbl), EndY(self.genderCell), ViewWidth(photoTitleLbl), PSCellHeight) title:@"出生年月" text:((self.infoModel && self.infoModel.birthday)?self.infoModel.birthday:@"") placeholder:@"请选择" cellType:PSCellTypeOfIndicator];
    self.birthdayCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.birthdayPickerView.hidden = NO;
    };
    [bottomScrollView addSubview:self.birthdayCell];
    
    self.experienceCell = [[PSCell alloc] initWithFrame:CGRectMake(StartX(photoTitleLbl), EndY(self.birthdayCell), ViewWidth(photoTitleLbl), PSCellHeight) title:@"工作经验" text:((self.infoModel && self.infoModel.experience_cn)?self.infoModel.experience_cn:@"") placeholder:@"请选择" cellType:PSCellTypeOfIndicator];
    self.experienceCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        strongSelf.experiencePickerView.hidden = NO;
    };
    [bottomScrollView addSubview:self.experienceCell];
    
    self.addressCell = [[PSCell alloc] initWithFrame:CGRectMake(StartX(photoTitleLbl), EndY(self.experienceCell), ViewWidth(photoTitleLbl), PSCellHeight) title:@"居住地" text:((self.infoModel && self.infoModel.residence)?self.infoModel.residence:@"") placeholder:@"请选择" cellType:PSCellTypeOfIndicator];
    self.addressCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        SelcetCityViewController *SCVC = [[SelcetCityViewController alloc] init];
        SCVC.delegate = strongSelf;
        [strongSelf.navigationController pushViewController:SCVC animated:YES];
    };
    [bottomScrollView addSubview:self.addressCell];
    
    self.phoneNumberCell = [[PSCell alloc] initWithFrame:CGRectMake(StartX(photoTitleLbl), EndY(self.addressCell), ViewWidth(photoTitleLbl), PSCellHeight) title:@"手机号" text:((self.infoModel && self.infoModel.telephone)?self.infoModel.telephone:nil) placeholder:@"请填写" cellType:PSCellTypeOfIndicator];
//    phoneNumberCell.textField.textColor = THEMECOLOR_OF_TEXT_cccccc;
    self.phoneNumberCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        LYSettingchangeMobileController *mobileVC = [[LYSettingchangeMobileController alloc] init];
        mobileVC.mobile = UD_GetOForK(isMobile);
        mobileVC.block = ^(){
            strongSelf.phoneNumberCell.textField.text = UD_GetOForK(isMobile);
        };
        [strongSelf.navigationController pushViewController:mobileVC animated:YES];
        
//        [strongSelf pushInfoEditVC:InfoEditTypeOfPhoneNumber];
    };
    [bottomScrollView addSubview:self.phoneNumberCell];
    
    self.emailCell = [[PSCell alloc] initWithFrame:CGRectMake(StartX(photoTitleLbl), EndY(self.phoneNumberCell), ViewWidth(photoTitleLbl), PSCellHeight) title:@"邮箱" text:((self.infoModel && self.infoModel.email)?self.infoModel.email:@"") placeholder:@"请填写" cellType:PSCellTypeOfIndicator];
    self.emailCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf pushInfoEditVC:InfoEditTypeOfEmail];
    };
    [bottomScrollView addSubview:self.emailCell];
    
    self.wxQRCodeCell = [[PSCell alloc] initWithFrame:CGRectMake(StartX(photoTitleLbl), EndY(self.emailCell), ViewWidth(photoTitleLbl), PSCellHeight) title:@"微信二维码" text:((self.infoModel && self.infoModel.weixin)?self.infoModel.weixin:@"") placeholder:@"请填写微信号并上传二维码" cellType:PSCellTypeOfIndicator];
    self.wxQRCodeCell.tap = ^{
        __strong __typeof(weakSelf)strongSelf = weakSelf;
        MineInfoEditWXQRCodeViewController *MIEWXVC = [[MineInfoEditWXQRCodeViewController alloc] init];
        MIEWXVC.delegate = strongSelf;
        if (strongSelf.infoModel.weixin) {
            MIEWXVC.wxID = strongSelf.infoModel.weixin;
        }
        if (strongSelf.infoModel.weixin_img) {
            MIEWXVC.wxURL = strongSelf.infoModel.weixin_img;
        }
        [strongSelf.navigationController pushViewController:MIEWXVC animated:YES];
    };
    [bottomScrollView addSubview:self.wxQRCodeCell];
    
    bottomScrollView.contentSize = CGSizeMake(0, EndY(self.wxQRCodeCell)+20*Scale);
}
- (void)okBtnTap {
    if (url && url.length) {
    } else {
        SVPHUDError(PersonalHeaderAlertText);
        return;
    }
    
    if (self.nicknameCell.textField.text.length>0) {
        if (self.genderCell.textField.text.length>0) {
            if (self.birthdayCell.textField.text.length>0) {
                if (self.experienceCell.textField.text.length>0) {
                    if (self.addressCell.textField.text.length>0) {
                        if (self.emailCell.textField.text.length>0) {
                            if (self.wxQRCodeCell.textField.text.length>0) {
                                [self upDate];
                            } else {
                                SVPHUDError(WXIDOKAlertText);
                            }
                        } else {
                            SVPHUDError(EmailAlertText);
                        }
                    } else {
                        SVPHUDError(PersonalAddressAlertText);
                    }
                } else {
                    SVPHUDError(PersonalExperienceAlertText);
                }
            } else {
                SVPHUDError(BirthdayAlertText);
            }
        } else {
            SVPHUDError(GenderAlertText);
        }
    } else {
        SVPHUDError(NICKNameAlertText);
    }
}
- (void)upDate {
    SVPHUDShow;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
    dic = [UIToolsControl getPublicParameter];
    [dic setObject:(UD_GetOForK(isResumeID)?UD_GetOForK(isResumeID):@"") forKey:@"resume_id"];
    [dic setObject:self.nameCell.textField.text forKey:@"name"];
    [dic setObject:self.nicknameCell.textField.text forKey:@"nickname"];
    [dic setObject:sex forKey:@"sex"];
    [dic setObject:url forKey:@"avatar"];
    [dic setObject:self.birthdayCell.textField.text forKey:@"birthday"];
    [dic setObject:experience forKey:@"experience"];
    [dic setObject:residence forKey:@"residence"];
    [dic setObject:self.phoneNumberCell.textField.text forKey:@"telephone"];
    [dic setObject:self.emailCell.textField.text forKey:@"email"];
    [dic setObject:self.wxQRCodeCell.textField.text forKey:@"weixin"];
    [dic setObject:wxPath forKey:@"weixin_img"];
    __weak __typeof(self)weakSelf = self;
    [BaseNetManager requestWithMethod:POST path:Person_SaveProfile_URL params:dic successBlock:^(NSDictionary *responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            __strong __typeof(weakSelf)strongSelf = weakSelf;
            SVPHUDSuccess(responseObject[@"msg"]);
            if (strongSelf.infoModel.avatar && strongSelf.infoModel.avatar.length) {
            } else {
                strongSelf.headerImg(self->url);
            }
            [self performSelector:@selector(delayClick) withObject:nil afterDelay:0.5];
        } else {
            SVPHUDError(responseObject[@"msg"]);
        }
    } failurBlock:^(NSError *error) {
        SVPHUDError(NetErrorAlertText);
    }];
}
- (void)delayClick {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)mineInfoEditWXQRCodeViewControllerInfo:(NSString *)wxID {
    self.wxQRCodeCell.textField.text = wxID;
}
- (void)mineInfoEditWXQRCodeViewControllerInfoWXImgPath:(NSString *)wxID {
    wxPath = wxID;
}
- (void)selcetCityViewControllerInfo:(NSDictionary *)dic {
    if ([[NSString stringWithFormat:@"%@", dic[@"cityid"]] integerValue] == 0) {
        self.addressCell.textField.text = [NSString stringWithFormat:@"%@", dic[@"province"]];
        residence = [NSString stringWithFormat:@"%@", dic[@"province"]];
    } else {
        self.addressCell.textField.text = [NSString stringWithFormat:@"%@-%@", dic[@"province"], dic[@"city"]];
        residence = [NSString stringWithFormat:@"%@-%@", dic[@"province"], dic[@"city"]];
    }
    
//    residence = dic[@"cityid"];
//    [NSString stringWithFormat:@"%@%@-%@%@-%@%@", dic[@"province"], dic[@"provinceid"], dic[@"city"], dic[@"cityid"], dic[@"area"], dic[@"areaid"]]
}
- (void)mineInfoEditViewController:(NSString *)info type:(InfoEditType)type {
    switch (type) {
        case InfoEditTypeOfName: {
            self.nameCell.textField.text = info;
        } break;
        case InfoEditTypeOfNickName: {
            self.nicknameCell.textField.text = info;
        } break;
        case InfoEditTypeOfPhoneNumber: {
            self.phoneNumberCell.textField.text = info;
        } break;
        case InfoEditTypeOfEmail: {
            self.emailCell.textField.text = info;
        } break;
        default:
            break;
    }
}
- (void)photoBtnTap {
   headerPickerView.hidden = NO;
}
- (void)psSingleRowViewCancel:(PSSingleRowView *)psSingleRowView {
    psSingleRowView.hidden = YES;
}
- (void)psSingleRowViewOk:(PublicCategoryElementModel *)model PSSingleRowView:(PSSingleRowView *)psSingleRowView {
    psSingleRowView.hidden = YES;
    if (psSingleRowView == headerPickerView) {
        if ([model.id integerValue] == 1) { // 相册
            [self openPhotoLibrary];
        } else { // 拍摄
            [self openCamera];
        }
    } else if (psSingleRowView == self.genderPickerView) {
        self.genderCell.textField.text = model.name;
        sex = model.id;
    } else if (psSingleRowView == self.experiencePickerView) {
        self.experienceCell.textField.text = model.name;
        experience = model.id;
    }
}
- (void)timeSelectPickerViewCancel:(TimeSelectPickerView *)timeSelectPickerView {
    timeSelectPickerView.hidden = YES;
}
- (void)timeSelectPickerViewOK:(NSString *)selectText timeSelectPickerView:(TimeSelectPickerView *)timeSelectPickerView {
    timeSelectPickerView.hidden = YES;
    self.birthdayCell.textField.text = selectText;
}

- (void)pushInfoEditVC:(InfoEditType)type {
    MineInfoEditViewController *MIEVC = [[MineInfoEditViewController alloc] init];
    MIEVC.type = type;
    MIEVC.delegate = self;
    switch (type) {
//        case InfoEditTypeOfName: {
//            if (nameCell.textField.text) {
//                MIEVC.text = nameCell.textField.text;
//            }
//        } break;
        case InfoEditTypeOfNickName: {
            if (self.nicknameCell.textField.text) {
                MIEVC.text = self.nicknameCell.textField.text;
            }
        } break;
        case InfoEditTypeOfPhoneNumber: {
            if (self.phoneNumberCell.textField.text) {
                MIEVC.text = self.phoneNumberCell.textField.text;
            }
        } break;
        case InfoEditTypeOfEmail: {
            if (self.emailCell.textField.text) {
                MIEVC.text = self.emailCell.textField.text;
            }
        } break;
        default:
            break;
    }
    [self.navigationController pushViewController:MIEVC animated:YES];
}
- (void)openCamera {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    
    AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied) { // 无权限
        CustomView *alertView = [[CustomView alloc] initWithTitle:@"相机权限未开启" message:@"相机权限未开启，请进入系统【设置】>【隐私】>【相机】中打开开关,开启相机功能" prompt:nil sureBtn:@"确定" cancleBtn:@"取消" size:170];
        alertView.resultIndex = ^(NSInteger index) { //回调---处理一系列动作
            if (index == 2) {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
            }
        };
        [alertView showXLAlertView];
    } else { // 有权限
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:picker animated:YES completion:nil];
    }
}
- (void)openPhotoLibrary {
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied) { // 无权限
        CustomView *alertView = [[CustomView alloc] initWithTitle:@"相册权限未开启" message:@"相册权限未开启，请进入系统【设置】>【隐私】>【相册】中打开开关,开启相册功能" prompt:nil sureBtn:@"确定" cancleBtn:@"取消" size:170];
        alertView.resultIndex = ^(NSInteger index) { //回调---处理一系列动作
            if (index == 2) {
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
            }
        };
        [alertView showXLAlertView];
    } else { // 有权限
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.allowsEditing = YES;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.delegate = self;
        imagePicker.navigationBar.translucent = NO;
        imagePicker.modalPresentationStyle = UIModalPresentationFullScreen;
        [self presentViewController:imagePicker animated:YES completion:^{
            NSLog(@"打开相册");
        }];
    }
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    NSLog(@"finish..");
    UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
    SVPHUDShow;
    [DataToolsControl uploadImgType:UploadImgTypeOfHeader image:image successBlock:^(NSDictionary *responseObject) {
        if ([responseObject[@"code"] integerValue] == 2000) {
            id data = responseObject[@"data"];
            self->url = data[@"url"];
            self->photoImgView.image = image;
            SVPHUDDismiss;
        } else {
            SVPHUDError(responseObject[@"msg"]);
        }
    } failurBlock:^(NSError *error) {
        SVPHUDError(@"上传失败，请重新操作");
    }];
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
